/**
 * Project Name:swt-hello <br/>
 * File Name:App.java <br/>
 * Package Name:com.ftu.z <br/>
 */
package com.ftu.swt.basic1;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;


/**
 * <p>  </p>
 * @version 1.0 2018年11月22日 mq 修改内容:初版
 */
public class UsingSystemTray {
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell1 = new Shell(display);
        shell1.setText("shell1");
        shell1.setSize(400, 400);
        
        Tray sysTray = display.getSystemTray();
        TrayItem item = new TrayItem(sysTray, SWT.NONE);
        item.setImage(display.getSystemImage(SWT.ICON_ERROR));
        item.setToolTipText("Test Tray");
        
        final Menu menu = new Menu(shell1, SWT.POP_UP);
        MenuItem item2 = new MenuItem(menu, SWT.PUSH);
        item2.setText("item 1");
        MenuItem item3 = new MenuItem(menu, SWT.PUSH);
        item3.setText("item 1");
        
        item.addListener(SWT.MenuDetect, new Listener() {
            @Override
            public void handleEvent(Event paramEvent) {
                menu.setVisible(true);
            }
        });
        item2.addSelectionListener(new SelectionAdapter() {
            /* (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
                shell1.dispose();
            }
        });
        
        shell1.open();
        while(!shell1.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }
        item.dispose();
        display.dispose();
        
    }

}
